// 项目管理模块
export function initProjectsModule(invoke) {
  let projects = [];

  return {
    loadProjects,
    updateProjectSelect,
    getProjects: () => projects
  };

  // 加载项目列表
  async function loadProjects() {
    try {
      projects = await invoke('get_all_projects');
      updateProjectSelect();
    } catch (error) {
      console.error('加载项目失败:', error);
    }
  }

  // 更新项目选择器
  function updateProjectSelect() {
    const select = document.getElementById('todo-project');
    select.innerHTML = '<option value="">无</option>';
    projects.forEach(project => {
      const option = document.createElement('option');
      option.value = project.id;
      option.textContent = project.name;
      select.appendChild(option);
    });
  }
}